import { adminLoginApi } from "@/apis/adminApi";
import { App, Button } from "antd"
import { useNavigate } from "react-router"

const LoginPage = () => {
    const navigate = useNavigate();
    const { message } = App.useApp();

    const onLogin = (data: object) => {
        adminLoginApi(data)
            .then(res => {
                if (res.code == 200) {
                    localStorage.adminToken = res.token;
                    message.success('登录成功');
                    navigate('/home', { replace: true });
                } else {
                    message.error(res.message);
                }
            })
    }


    return (
        <div>
            <h1>登录</h1>
            <Button type="primary" onClick={() => {
                onLogin({ account: 'zhangsan', password: '123' });
            }}>超管登录</Button>
            <Button type="primary" onClick={() => {
                onLogin({ account: 'lisi', password: '123' });
            }}>普管登录</Button>
            <Button type="primary" onClick={() => {
                onLogin({ account: 'wangwu', password: '123' });
            }}>按钮权限登录</Button>
        </div>
    )
}

export default LoginPage
